﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;

namespace AugustVisual
{
    [ToolboxItem(false)]
    public class RowLine : Grid
    {
        static RowLine()
        {
            DefaultStyleKeyProperty.OverrideMetadata(typeof(RowLine), new FrameworkPropertyMetadata(typeof(RowLine)));
        }
        public RowLine()
        {
            Focusable = false;
        }


        public AugustDataView AugustDataView
        {
            get { return (AugustDataView)GetValue(AugustDataViewProperty); }
            set { SetValue(AugustDataViewProperty, value); }
        }

        // Using a DependencyProperty as the backing store for AugustDataView.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty AugustDataViewProperty =
            DependencyProperty.Register("AugustDataView", typeof(AugustDataView), typeof(RowLine), new PropertyMetadata(null));



        internal void FreshBackColor(string mark, int index)
        {
            int markCount = 0;
            PropertyInfo[] propertyInfos = DataContext.GetType().GetProperties();
            for (int i = 0; i < propertyInfos.Length; i++)
            {
                if (propertyInfos[i].GetValue(DataContext).ToString() == mark)
                {
                    markCount++;
                }
            }
            if (markCount != 0)
            {
                MarkRowLine.Background = Brushes.Orange;
            }
            else
            {
                MarkRowLine.Background = Brushes.Transparent;
            }
            if (index % 2 == 0)
            {
                //var ff = AugustDataView.Background;
                DistinctRowLine.Background = Brushes.LightGreen;
            }
            else
            {
                DistinctRowLine.Background = Brushes.Transparent;
            }

        }


        private Grid distinctRowLine;
        public Grid DistinctRowLine
        {
            get
            {
                if (distinctRowLine == null)
                {
                    distinctRowLine = (Grid)FrameworkElementHelper.Findchild(this, "DistinctTwoLine");
                }
                return distinctRowLine;
            }
            set { distinctRowLine = value; }
        }

        private Grid markRowLine;
        public Grid MarkRowLine
        {
            get
            {
                if (markRowLine == null)
                {
                    markRowLine = (Grid)FrameworkElementHelper.Findchild(this, "MarkRowLine");
                }
                return markRowLine;
            }
            set { markRowLine = value; }
        }
    }
}
